<template>
	<view class="screen_box">
		<view class="screen_cont">
			<view class="screen_list">
				<text v-for="(item,index) in list" :key="item.id" :class="['',{'active':active.includes(item.id)}]"
					@click="chooseItem(item.id,item.name)">{{item.name}}</text>
			</view>
		</view>
		<view class="Submit_box">
			<text class="confirm" @click="confirm">确定</text>
			<text class="Reset" @click="active = []">重置</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentIndex: null,
				active: [], //多选选中效果和ID
				a_name: [],
				Arr:[]
			}
		},
		props: {
			list: {
				type: Array
			},
			type: {
				type: Number
			}
		},
		mounted() {},
		methods: {
			chooseItem(id, name) {
				if (this.active.includes(id)) {
					//includes()方法判断是否包含某一元素,返回true或false表示是否包含元素，对NaN一样有效
					let index = this.active.indexOf(id); // 判断数组中是否有选中的id,如果有则去掉
					if (index > -1) {
						this.active.splice(index, 1)
						this.a_name.splice(index, 1)
						this.Arr.splice(index, 1)
					}
				} else {
					this.active.push(id)
					this.a_name.push(name)
					let obj={
						name:name,
						id:id
					}
					this.Arr.push(obj)
				}
			},
			confirm() {
				if (this.active.length > 0) {
					this.$emit("send", this.active, this.a_name, this.type,this.Arr)
				} else {
					uni.showToast({
						title: '请选择',
						icon: 'none',
						duration: 3000
					})
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.screen_box {
		padding: 20rpx 20rpx 0 20rpx;
		box-sizing: border-box;
		width: 70vw;

		.screen_cont {
			overflow-y: auto;
			height: 90vh;

			.screen_list {
				display: flex;
				flex-wrap: wrap;

				text {
					// flex: 1;
					background-color: #f6f6f6;
					border: #f6f6f6 solid 1px;
					color: #333;
					font-size: 24rpx;
					padding: 15rpx;
					width: 100%;
					border-radius: 20rpx;
					text-align: center;
					margin: 20rpx;
					// margin: 10rpx calc(10% / 2) 19rpx 0;
					box-sizing: border-box;
				}

				// text:nth-child(3n) {
				// 	margin-right: 0 !important;
				// }

				.active {
					border: #1688f1 solid 1px;
					box-sizing: border-box;
					color: #1688f1;
				}
			}
		}

		.Submit_box {
			display: flex;

			text {
				width: 50%;
				text-align: center;
				padding: 20rpx 0;
				box-sizing: border-box;
				display: block;
				margin: 20rpx 0;
			}

			.confirm {
				background-color: #1688f1;
				color: #fff;
			}

			.Reset {
				background-color: #f6f6f6;
				color: #333;
			}
		}
	}
</style>